package edu.ksu.cis.indus.tools;

import edu.ksu.cis.indus.common.scoping.JiBX_MungeAdapter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jibx.runtime.IMarshallable;
import org.jibx.runtime.IMarshaller;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallable;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.impl.MarshallingContext;
import org.jibx.runtime.impl.UnmarshallingContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class CompositeToolConfiguration extends AbstractToolConfiguration
  implements IUnmarshallable, IMarshallable
{
  private static final Logger LOGGER = LoggerFactory.getLogger(CompositeToolConfiguration.class);

  final List configurations = new ArrayList();
  private String activeConfigID;
  public static final String JiBX_bindingList = "|edu.ksu.cis.indus.tools.JiBX_slicerConfig_JiBXBindingFactory|";

  public static List createConfigurations()
  {
    return new ArrayList();
  }

  public void setActiveToolConfiguration(IToolConfiguration config)
  {
    if (this.configurations.contains(config)) {
      this.activeConfigID = config.getConfigName();
    }
    else if (LOGGER.isWarnEnabled())
      LOGGER.warn("The given configuration is not part of this collection.  It was not activated.");
  }

  public void setActiveToolConfigurationID(String id)
  {
    if (this.configurations.isEmpty()) {
      this.activeConfigID = id;
    } else {
      String _temp = null;

      for (Iterator _i = this.configurations.iterator(); _i.hasNext(); ) {
        IToolConfiguration _config = (IToolConfiguration)_i.next();

        if (_config.getConfigName().equals(id)) {
          _temp = id;
        }
      }

      if (_temp != null) {
        this.activeConfigID = _temp;
      } else {
        String _msg = 
          "setActiveToolConfigurationID(id = " + id + ") - Configuration with given ID does not exist.";
        LOGGER.error(_msg);
        throw new RuntimeException(_msg);
      }
    }
  }

  public String getActiveToolConfigurationID()
  {
    return getActiveToolConfiguration().getConfigName();
  }

  public void addToolConfiguration(IToolConfiguration config)
  {
    if (config == null) {
      if (LOGGER.isWarnEnabled()) {
        LOGGER.warn("Null configurations are not supported.");
      }
    }
    else if (this.configurations.contains(config)) {
      if (LOGGER.isWarnEnabled())
        LOGGER.warn("The given configurationCollection exists.");
    }
    else
      this.configurations.add(config);
  }

  public void initialize()
  {
  }

  public void setConfigurations(List configs)
  {
    this.configurations.clear();
    this.configurations.addAll(configs);
  }

  protected boolean processProperty(Object propertyID, Object value)
  {
    IToolConfiguration _ac = getActiveToolConfiguration();
    return ((AbstractToolConfiguration)_ac).processProperty(propertyID, value);
  }

  IToolConfiguration getActiveToolConfiguration()
  {
    IToolConfiguration _result = null;

    for (Iterator _i = this.configurations.iterator(); _i.hasNext(); ) {
      IToolConfiguration _config = (IToolConfiguration)_i.next();

      if (_config.getConfigName().equals(this.activeConfigID)) {
        _result = _config;
        break;
      }
    }

    if (_result == null) {
      if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Selecting the first configuration as active configurationCollection.");
      }

      _result = (IToolConfiguration)this.configurations.get(0);

      if (_result != null)
        this.activeConfigID = _result.getConfigName();
      else {
        throw new RuntimeException("There are no configurations.");
      }
    }

    return _result;
  }

  public static CompositeToolConfiguration JiBX_slicerConfig_JiBXBinding_newinstance_2_0(UnmarshallingContext arg1)
    throws JiBXException
  {
    return new CompositeToolConfiguration();
  }

  public final CompositeToolConfiguration JiBX_slicerConfig_JiBXBinding_unmarshalAttr_2_0(UnmarshallingContext arg1)
    throws JiBXException
  {
    arg1.pushTrackedObject(this);
    setActiveToolConfigurationID(arg1.attributeText("http://indus.projects.cis.ksu.edu/indus", "activeConfiguration"));
    arg1.popObject();
    return this;
  }

  public final CompositeToolConfiguration JiBX_slicerConfig_JiBXBinding_unmarshal_2_0(UnmarshallingContext arg1)
    throws JiBXException
  {
    arg1.pushObject(this);
//    List tmp11_8 = this.configurations;
//    if (tmp11_8 == null)
//      tmp11_8;
//    tmp11_8.configurations = JiBX_MungeAdapter.JiBX_slicerConfig_JiBXBinding_unmarshal_1_6(JiBX_MungeAdapter.JiBX_slicerConfig_JiBXBinding_newinstance_1_6(arg1), arg1);
    arg1.popObject();
    return this;
  }

  public void unmarshal(IUnmarshallingContext arg1)
    throws JiBXException
  {
  }

  public final void JiBX_slicerConfig_JiBXBinding_marshalAttr_2_0(MarshallingContext arg1)
    throws JiBXException
  {
    arg1.pushObject(this);
    arg1.popObject();
  }

  public final void JiBX_slicerConfig_JiBXBinding_marshal_2_0(MarshallingContext arg1)
    throws JiBXException
  {
    arg1.pushObject(this);
    JiBX_MungeAdapter.JiBX_slicerConfig_JiBXBinding_marshal_1_6(this.configurations, arg1);
    arg1.popObject();
  }

  public void marshal(IMarshallingContext arg1)
    throws JiBXException
  {
    arg1.getMarshaller(8, "edu.ksu.cis.indus.tools.CompositeToolConfiguration").marshal(this, arg1);
  }

  public int JiBX_getIndex()
  {
    return 8;
  }
}

/* Location:           D:\tool\banderaCLI-1.0a4\lib\indus\indus.jar
 * Qualified Name:     edu.ksu.cis.indus.tools.CompositeToolConfiguration
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.5.3
 */